package com.bang.low.index;

import com.bang.EsUtils;
import org.apache.http.StatusLine;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;

/**
 * @ClassName: DeleteIndex
 * @Desc: TODO
 * @author: <Bang>
 * @Date: 2022/01/18 16:26
 * @Version: 1.0
 * @Modified By:
 */
public class DeleteIndex {

    public static void main(String[] args) throws Exception{
        final RestClient lowLevelClient = EsUtils.getLowLevelClient();
        String index = "acbsdd";
        final Request request = new Request("DELETE", "/" + index);

        try {
            final Response response = lowLevelClient.performRequest(request);
            final StatusLine statusLine = response.getStatusLine();
            final int statusCode = statusLine.getStatusCode();
            String responseBody = EntityUtils.toString(response.getEntity());
            System.out.println("statusCode:" + statusCode);
            System.out.println("response:" + responseBody);


        } catch (ResponseException e) {
            final Response response = e.getResponse();
            final StatusLine statusLine = response.getStatusLine();
            String responseBody = EntityUtils.toString(response.getEntity());
            System.out.println("statusCode:" + statusLine.getStatusCode());
            System.out.println("response:" + responseBody);
        }
        lowLevelClient.close();
    }
}
